package com.effectiv.gooruda.rest.api.operation;



import javax.ws.rs.core.MediaType;

import com.effectiv.gooruda.rest.api.domain.Cache;
import com.effectiv.gooruda.rest.api.domain.CacheEntry;
import com.effectiv.gooruda.rest.docs.core.annotation.Api;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiBodyObject;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiHeader;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiHeaders;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiMethod;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiParam;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiResponseObject;
import com.effectiv.gooruda.rest.docs.core.pojo.ApiVerb;

@Api(name = "Cache API", description = "Cache API.")
public interface CacheOperation {
	@ApiMethod(path = "/cache/findone/{cacheName}", verb = ApiVerb.GET, description = "Find details about a cache.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	Cache findOne(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName);
	
	@ApiMethod(path = "/cache/{cacheName}/key/{key}", verb = ApiVerb.POST, description = "Add an entry in the cache.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	void addEntry(
			@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName,
			@ApiParam(name = "key", required = true, description = "Name of the key.")String key,  
			@ApiBodyObject CacheEntry entry);
	
	
	@ApiMethod(path = "/cache/{cacheName}/key/{key}", verb = ApiVerb.GET, description = "Gets an entry from the cache.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	CacheEntry getEntry(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName,
			@ApiParam(name = "key", required = true, description = "Name of the key.")String key);
	
	@ApiMethod(path = "/cache/{cacheName}", verb = ApiVerb.DELETE, description = "Delete a cache with the given name.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	Cache delete(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName);
	
	@ApiMethod(path = "/cache/{cacheName}", verb = ApiVerb.DELETE, description = "Removes all entries from a cache with the given name.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	
	void clear(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName);
	
	@ApiMethod(path = "/cache/{cacheName}/key/{key}/remove", verb = ApiVerb.DELETE, description = "Removes an entry with given key from a cache with the given name.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	CacheEntry removeEntry(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName,
			@ApiParam(name = "key", required = true, description = "Name of the key.")String key);	
	
	
	@ApiMethod(path = "/cache/{cacheName}/key/{key}/increment", verb = ApiVerb.POST, 
			description = "Increments the value of the given entry by 1. The type is auto-detected to be integer. If it is of any other type, increment will result in error.", 
			produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	CacheEntry increment(@ApiParam(name = "cacheName", required = true, description = "Name of the cache.") String cacheName,
			@ApiParam(name = "key", required = true, description = "Name of the key.")String key);
	
	//List<Cache> listCaches();
	//List<CacheEntry> findAll(String cacheName, String selector);
}
